package algo;

public class Fifo {
	private Maillon first;
	private Maillon last;
	public Fifo(){
		first = null;
		last = null;
	}
	public void addElem (int o){
		if (isEmpty()){
			last = new Maillon (o, null);
			first = last;
		}else{
			last.setNext(new Maillon (o, null));
			last.setNext(last.getNext());
		}
	}
	
	public int getFirst (){
		return first.getValeur();
	}
	
	public int getLast(){
		return last.getValeur();
	}
	
	public boolean isEmpty (){
		return first == null;
	}
	
	public Fifo deleteElem (){
		if (!isEmpty()){
			first = first.getNext();
			if(first == null){
				last = null;
			}
		}
		return this;
	}

	public String toString (){
		if (first != null){
			StringBuffer sb = new StringBuffer("[" + first);
			Maillon m = first.getNext();
			while (m != null){
				sb.append("|" + m);
				m = m.getNext();
			}
			sb.append("]");
			return sb.toString();
		}else{
			return "[]";
		}
	}
	
}
